/*******************************************************************************
 * Copyright (c) 2008 meihuichina.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Actuate Corporation  - initial API and implementation
 *******************************************************************************/

package org.langqiao.oop.clone.deep;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

/**
 * 
 */

public class Student2 implements Serializable {
	private static final long serialVersionUID = 1L;
	String name;// 常量对象。
    int age;
    Professor2 p;// 学生1和学生2的引用值都是一样的。
 
    Student2(String name, int age, Professor2 p) {
        this.name = name;
        this.age = age;
        this.p = p;
    }
 
    public Object deepCopy() throws IOException, ClassNotFoundException {
    	ByteArrayOutputStream bo = new ByteArrayOutputStream();
    	ObjectOutputStream oo = new ObjectOutputStream( bo );
    	oo.writeObject( this );
    	
    	ByteArrayInputStream bi = new ByteArrayInputStream(bo.toByteArray( ));
    	ObjectInputStream oi = new ObjectInputStream(bi);
        return oi.readObject( );
    }
}
